package com.magicsoft.share.presenter.exchange;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.exchange.GoodsType;
import com.magicsoft.share.bean.share.Banner;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.view.exchange.IExchangeView;

import java.util.List;

import io.reactivex.annotations.NonNull;

/**
 * Created by lyf on 2017/11/30/030.
 */

public class ExchangePresenter extends BasePresenter<IExchangeView> {
    public void bannerList() {
        RetrofitUtil.getApi(APIService.class)
                .bannerList(2)
                .compose(new NetWorkTransformer<List<Banner>>())
                //  .compose(new LoadingTransformer<List<Banner>>(mContext))
                .subscribe(new SimpleObserver<List<Banner>>(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull List<Banner> banners) {

                        if (null != getView()) {
                            getView().bannerListSuccess(banners);
                        }
                    }
                });
    }

    public void goodsTypeList() {
        RetrofitUtil.getApi(APIService.class)
                .goodsTypeList()
                .compose(new NetWorkTransformer<List<GoodsType>>())
                //  .compose(new LoadingTransformer<List<Banner>>(mContext))
                .subscribe(new SimpleObserver<List<GoodsType>>(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull List<GoodsType> goodsTypes) {

                        if (null != getView()) {
                            getView().goodsTypeListSuccess(goodsTypes);
                        }
                    }
                });
    }
}
